package com.tonann.app.controller;

import com.tonann.app.domain.AppOneKeyRepair;
import com.tonann.app.service.IAppOneKeyRepairService;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.core.page.TableDataInfo;
import com.tonann.common.enums.BusinessType;
import com.tonann.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 一键报修Controller
 *
 * @author tonann
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/app/oneKeyRepair")
public class AppOneKeyRepairController extends BaseController {
    @Autowired
    private IAppOneKeyRepairService appOneKeyRepairService;

    /**
     * 查询一键报修列表
     */
    @PreAuthorize("@ss.hasPermi('app:oneKeyRepair:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppOneKeyRepair appOneKeyRepair) {
        startPage();
        List<AppOneKeyRepair> list = appOneKeyRepairService.selectAppOneKeyRepairList(appOneKeyRepair);
        return getDataTable(list);
    }

    /**
     * 导出一键报修列表
     */
    @PreAuthorize("@ss.hasPermi('app:oneKeyRepair:export')")
    @Log(title = "一键报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppOneKeyRepair appOneKeyRepair) {
        List<AppOneKeyRepair> list = appOneKeyRepairService.selectAppOneKeyRepairList(appOneKeyRepair);
        ExcelUtil<AppOneKeyRepair> util = new ExcelUtil<AppOneKeyRepair>(AppOneKeyRepair.class);
        util.exportExcel(response, list, "一键报修数据");
    }

    /**
     * 获取一键报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:oneKeyRepair:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(appOneKeyRepairService.selectAppOneKeyRepairById(id));
    }

    /**
     * 新增一键报修
     */
    @PreAuthorize("@ss.hasPermi('app:oneKeyRepair:add')")
    @Log(title = "一键报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppOneKeyRepair appOneKeyRepair) {
        return toAjax(appOneKeyRepairService.insertAppOneKeyRepair(appOneKeyRepair));
    }

    /**
     * 修改一键报修
     */
    @PreAuthorize("@ss.hasPermi('app:oneKeyRepair:edit')")
    @Log(title = "一键报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppOneKeyRepair appOneKeyRepair) {
        return toAjax(appOneKeyRepairService.updateAppOneKeyRepair(appOneKeyRepair));
    }

    /**
     * 删除一键报修
     */
    @PreAuthorize("@ss.hasPermi('app:oneKeyRepair:remove')")
    @Log(title = "一键报修", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appOneKeyRepairService.deleteAppOneKeyRepairByIds(ids));
    }
}
